//
//  main.m
//  oc_9
//
//  Created by 楼楚 on 15/9/11.
//  Copyright (c) 2015年 Chu Lou. All rights reserved.
//

#import <Foundation/Foundation.h>

int main(int argc, const char * argv[]) {
    @autoreleasepool {
//        char *str = "hello world";
//        NSLog(@"%s",str);
   //    NSString *str1 = @"hello world";//声明一个常量字符串的方法
   //    NSString *str2 = [[NSString alloc] initWithString:str1];// 通过一个已知字符串，生成一个新的字符串
     //  NSString *str3 = [[NSString alloc] initWithUTF8String:"hello world"];//这是表示用一个c语言的字符串生成一个oc当中的字符串
   //    NSString *str4 = [[NSString alloc] initWithFormat:@"hell%c wor%@",'o',@"ld" ];
        
   //    NSLog(@"str1 is - %@",str1);
   //    NSLog(@"str2 is - %@",str2);
   //    NSLog(@"str3 is - %@",str3);
   //    NSLog(@"str4 is - %@",str4);
        
   //     NSString *str5 = [NSString stringWithString:str1];
   //     NSString *str6 = [NSString stringWithUTF8String:"hello world"];
   //     NSString *str7 = [NSString stringWithFormat:@"hell%c wor%@",'o',@"ld" ];
       
    //    NSLog(@"str5 is - %@",str5);
   //     NSLog(@"str6 is - %@",str6);
    //    NSLog(@"str7 is - %@",str7);
        
        NSString *str1 = @"1234567890";
        NSString *str2 = @"1234567890";
        NSString *str3 = @"1234";
        BOOL ret = [str1 isEqualToString:str3];//比较两个字符串是否相同的方法
        
        NSComparisonResult result = [str1 compare:str3];
        if (result == NSOrderedAscending) {
            NSLog(@"str1<str2");
        }
        else if (result == NSOrderedDescending){
            NSLog(@"str1 > str2");
            
        }
        else if (result == NSOrderedSame){
            NSLog(@"str1 == str2");
        }
        NSLog(@"%d",ret);
        
        
        NSString *str4 = [str1 substringToIndex:6];//通过字符串的切割得到新的字符串 原字符串不变
        
        NSLog(@"%@",str4);
        
        NSString *str5 = [str1 substringFromIndex:6];//从第六位开始截取 得到新的字符串 原字符串不变
        
        NSLog(@"%@",str5);
        
        NSString *str6 = [str1 substringWithRange:NSMakeRange(6, 2)];//  从第六位开始截取两位，指定范围截取
        
        NSLog(@"%@",str6);
        
        NSRange range = [str1 rangeOfString:str3];
        
        if (range.length > 0) {
            NSLog(@"str1 中含有字符串 str3");
        }
      //  NSLog(@"%@",range);
        NSLog(@"%zd %zd",range.location,range.length);
    }
    return 0;
}
